package com.example.sherlockzhong.plush_v2;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

import com.example.sherlockzhong.plush_v2.CardIni.ScheduleIni;
import com.example.sherlockzhong.plush_v2.View.WelcomeHorizontalScrollFullView;
import com.umeng.analytics.MobclickAgent;


/*
 * Created by Administrator on 2014/9/15.
 */
public class WelcomeActivity extends Activity {
    ImageView splash_img;
    Button start;
    WelcomeHorizontalScrollFullView welocmefull_inside;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        boolean status = welcomeStatus();
        if (status) {
            Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
            startActivity(intent);
            //overridePendingTransition(R.anim.fade, R.anim.hold);
            finish();
        } else {
            initWidget();
            initScroll();
            final Animation fade = AnimationUtils.loadAnimation(WelcomeActivity.this, R.anim.alpha);
            fade.setFillAfter(true);
            splash_img.startAnimation(fade);
            welocmefull_inside.setVisibility(View.VISIBLE);
        }
    }

    //初始化开始按钮
    private void initWidget() {
        splash_img = (ImageView) findViewById(R.id.splash_img);
        start = (Button) findViewById(R.id.welcome_button);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fade, R.anim.hold);
                finish();
            }
        });
    }

    //初始化scroll
    private void initScroll() {
        Display display = getWindowManager().getDefaultDisplay();
        Point p = new Point();
        display.getSize(p);
        final int windowWidth = p.x;
        welocmefull_inside = (WelcomeHorizontalScrollFullView) findViewById(R.id.welcomefull_inside);
        welocmefull_inside.setApp(this);
        ScheduleIni.shapeWelcomeHorizontalScrollViewFull(this, welocmefull_inside);
        welocmefull_inside.setScrollDistance(windowWidth);
    }

    private boolean welcomeStatus() {
        SharedPreferences preferences = getSharedPreferences("user", MODE_PRIVATE);
        boolean status = preferences.getBoolean("status", false);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("status", true);
        editor.commit();
        return status;
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

}
